import request, { type ListQuery, type ListResponse } from "@/utils/request";
import { type ThirdAppType } from "./third-app";

const BASE_URL = "/api/internal/ApiKeys";

const APIKEYAPI = {
  getApiKeyList: (params: ApiKeyListParams) => {
    return request.get<any, ListResponse<ApiKeyType>>(`${BASE_URL}/`, {
      params,
    });
  },
  addApiKey: (data: ApiKeyForm) => {
    return request.post(`${BASE_URL}/`, data);
  },
  updateApiKey: (data: Partial<ApiKeyForm>) => {
    return request.put(`${BASE_URL}/${data.id}/`, data);
  },
  deleteApiKey: (id: number) => {
    return request.delete(`${BASE_URL}/${id}/`);
  },
};

export type ApiKeyListParams = {} & ListQuery;

export type ApiKeyType = {
  id: number;
  app: ThirdAppType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  key: string;
};

/**
 * @description API Key Form
 * @property {number} id - API Key ID
 * @property {number} app - 第三方应用id
 * @property {boolean} is_active - 是否有效
 * @property {string} key - API Key
 *
 */
export type ApiKeyForm = {
  id?: number;
  app: number | string;
  is_active: boolean;
  key: string;
};

export default APIKEYAPI;
